package com.reder.practice.controller;

import com.reder.practice.bean.Comment;
import com.reder.practice.bean.User;
import com.reder.practice.common.annotation.FromSession;
import com.reder.practice.common.dto.ServerResponse;
import com.reder.practice.common.util.PageUtil;
import com.reder.practice.service.CommentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

/**
 * 评论web层
 *
 * @author Red
 * <p>Email: 1318944013@qq.com</p>
 * <p>created by 2019/09/23 9:41</p>
 */
@RestController
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping(value = "/comments")
    @ApiOperation("展示评论列表")
    public ServerResponse listComment(long videoId,
                                      int pageNumber,
                                      @RequestParam(defaultValue = PageUtil.DEFAULT_SIZE_OF_ONE_PAGE + "") int sizeOfOnePage) {

        return commentService.listComment(videoId, pageNumber, sizeOfOnePage);
    }

    @PostMapping(value = "/comment")
    @ApiOperation("发表评论")
    public ServerResponse addComment(Comment comment, @ApiIgnore @FromSession User user) {

        return commentService.insertComment(comment, user);
    }

    @DeleteMapping(value = "/comment/{commentId}")
    @ApiOperation("删除评论")
    public ServerResponse deleteComment(@PathVariable("commentId") long commentId) {

        return commentService.deleteComment(commentId);
    }

}
